﻿var UnPublish = 0; //待发布
var Publish = 1; //已发布
var VirtualLink = 0; //虚链接
var RealLink = 1; //实链接
var IndexLink = 2; //索引链接

var NodeID = UrlParm.parm('nodeid');
var PubStatus = UrlParm.parm('state');

function setCheckAll(obj) {
    //alert(val);
    if (obj.checked) {
        CheckAll(obj.form);
    } else {
        UnSelectAll(obj.form);
    }
}



function getSelectVal() {//获取选择的值
    var selVal = '';
    $("[name='delid']").each(function() {
        if ($(this).attr('checked')) {
            if (selVal == '') {
                selVal = $(this).val();
            }
            else {
                selVal += ',' + $(this).val();
            }
        }
    });
    return selVal;
}
function doing(action, parm) {
    //alert(action);//测试用
    switch (action) {
        case 'editdoc':
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            var popupWin = window.open('admin_publish_eidt.aspx?ac=edit&nodeid=' + NodeID + '&id=' + parm, 'editor', 'width=800,height=600,scrollbars=no,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
            break;
        case 'note':
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            //window.open('admin_contribution.php?sId=0d20785d09f26ddd90fdb17bc55f9136&o=viewNote&NodeID=' + NodeID + '&ContributionID=' + IndexID, '', 'width=400,height=300,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
            alert("查看功能需要开发");
            break;
        case 'advanced_search':
            if (parm != '') {
                window.location = 'content_list.aspx?nodeid=' + NodeID + '&state=' + parm + '&offset=' + $("#offset").val();
            } else {
                window.location = 'content_list.aspx?nodeid=' + NodeID + '&offset=' + $("#offset").val()
            }
            break;

        case 'viewLinkState':
            //查看内容链接状态
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            window.open('content_viewLinkState.aspx?contentid=' + parm + '&nodeid=' + NodeID, '', 'width=400,height=300,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
            break;
        case 'topIt':
            //置顶
            show_dialog('content_save.aspx?ac=topIt&nodeid=' + NodeID + '&id=' + parm, 250, 50, '文章置顶权重设置');
            break;
        case 'pinkIt':
            //精华
            show_dialog('content_save.aspx?ac=pinkIt&nodeid=' + NodeID + '&id=' + parm, 250, 50, '文章精华权重设置');
            break;
        case 'sortIt':
            //排序
            show_dialog('content_save.aspx?ac=sortIt&nodeid=' + NodeID + '&id=' + parm, 250, 50, '文章排序权重设置');
            break;
        case 'viewpublish':
            var mPath = $('#URL_' + parm).attr('href');
            //eval('var mPath = URL_' + parm + '.href');
            window.open(mPath, "", "")

            break;
        case 'getURL':
            var mPath = $('#URL_' + parm).attr('href');
            //eval('var mPath = URL_' + parm + '.href');
            prompt("文章发布URL地址", mPath);
            break;
        case 'copyURL':
            var mPath = $('#URL_' + parm).attr('href');
            //eval('var mPath = URL_' + parm + '.href');
            //window.clipboardData.setData('Text', mPath);
            copy2Clipboard(mPath);
            break;
        case 'edit':
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            window.open('/cmsware/admin/admin_publish.php?sId=0d20785d09f26ddd90fdb17bc55f9136&type=main&o=content_editor_frameset&extra=edit&NodeID=' + NodeID + '&IndexID=' + IndexID, '', 'width=800,height=600,scrollbars=no,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);

            break;
        case 'del':
            if (confirm("确认删除吗?")) {
                var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_delete_doc&nodeid=' + NodeID + '&id=' + parm, async: false }).responseText;
                //alert(returntext); //调试错误信息
                var msg = eval("msg=" + returntext);
                if (msg.result == "1") {
                    alert("操作成功");
                    window.location.reload(true);
                }
                else {
                    alert(msg.msg); //出错信息

                }

            }
            break;
        case 'view':
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            window.open('content_view.aspx?nodeid=' + NodeID + '&id=' + parm, '', 'width=800,height=600,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);

            break;
        case 'cut':
            var parm = '?roottype=doccut&view=node_select&menu=tree_panel&cutcontentid=' + parm;
            show_dialog('../AdminSelect.aspx' + parm, 450, 310, '选择结点');
            break;
        case 'copy':
            var parm = '?roottype=doccopy&view=node_select&menu=tree_panel&copycontentid=' + parm;
            show_dialog('../AdminSelect.aspx' + parm, 450, 310, '选择结点');
            break;
        case 'createLink': //创建虚链接
            var parm = '?roottype=createlink&view=node_select&menu=tree_panel&contentid=' + parm;
            show_dialog('../AdminSelect.aspx' + parm, 450, 310, '选择结点');
            break;
        case 'createIndexLink': //创建索引链接
            var parm = '?roottype=createindexlink&view=node_select&menu=tree_panel&contentid=' + parm;
            show_dialog('../AdminSelect.aspx' + parm, 450, 310, '选择结点');
            break;
        case 'PubContent': //发布操作
            window.location.href = 'admin_publish.aspx?ac=PubContent&contentid=' + parm + '&nodeid=' + NodeID;
            break;
        case 'unpublish':
            // if (confirm("确认取消发布吗？\n\n警告！该操作将同时清空该文章相关的评论、计数等发布信息.\n\n建议你使用“临时取消发布”。")) {
            window.location.href = 'admin_publish.aspx?ac=ConcelPubContent&contentid=' + parm + '&nodeid=' + NodeID;
            // document.documentlist.referer.value = document.location;
            //document.documentlist.action = '/cmsware/admin/admin_publish.php?sId=0d20785d09f26ddd90fdb17bc55f9136&' + 'o=' + action + '&type=' + type + '&IndexID=' + IndexID + '&NodeID=' + NodeID + '&targetNodeID=' + targetNodeID;
            //document.documentlist.submit();
            //alert(IndexID + '-' + targetNodeID)
            // }
            break;
        case 'tempUnPublish':
            window.location.href = 'admin_publish.aspx?ac=ConcelPubContent&contentid=' + parm + '&nodeid=' + NodeID;
            //                    document.documentlist.referer.value = document.location;
            //                    document.documentlist.action = '/cmsware/admin/admin_publish.php?sId=0d20785d09f26ddd90fdb17bc55f9136&' + 'o=' + action + '&type=' + type + '&IndexID=' + IndexID + '&NodeID=' + NodeID + '&targetNodeID=' + targetNodeID;
            //                    document.documentlist.submit();
            //alert(IndexID + '-' + targetNodeID)
            break;
        case 'RePubContent': //更新
            window.location.href = 'admin_publish.aspx?ac=RePubContent&contentid=' + parm + '&nodeid=' + NodeID;
            break;
        case 'display_record':
            alert("查看功能需要开发");
            // parent.mainFrame.location = "admin_publish.php?sId=0d20785d09f26ddd90fdb17bc55f9136&o=content_list&type=main&NodeID=" + NodeID + "&offset=" + document.documentlist.offset.value;
            break;
        case 'date_search':
            var DateString = $('#txtPubTime').val();
            document.location = "content_search_result.aspx?nodeid=" + NodeID + "&offset=" + $('#offset').val() + "&Date=" + DateString;
            break;
        case 'keyword_search': 
            var KeywordsString = $('#SearchKeywords').val();
            document.location = "content_search_result.aspx?nodeid=" + NodeID + "&offset=" + $('#offset').val() + "&Keywords=" + KeywordsString;
            break;
        case 'search_pro':
            alert("查看功能需要开发");
            //var KeywordsString = document.getElementById('SearchKeywords');
            //parent.document.location = "admin_search.php?sId=0d20785d09f26ddd90fdb17bc55f9136&Tpl=content_admin_search.html&TableID=" + TableID + "&NodeID=" + NodeID + "&offset=" + document.documentlist.offset.value + "&Field=all&Keywords=" + KeywordsString.value;
            break;
        case 'offset':
            var str = '';
            var state = $("#ddlPublishStatus").val();
            if (state != '') {
                str = '&state' + state;
            }
            window.location.href = 'content_list.aspx?nodeid=' + NodeID + '&offset=' + $('#offset').val() + str;
            break;
        case 'plan':
            var selVal = getSelectVal();
            if (selVal == '') { alert('请选择要操作的内容'); return false; }
            var planDate = $('#txtDate').val() + '  ' + $('#ddlHour').val() + ':' + $('#ddlMinute').val() + ':' + $('#ddlSecond').val();
            var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_plan_doc&nodeid=' + NodeID + '&id=' + selVal + '&plandate=' + planDate, async: false }).responseText;
            alert(returntext); //调试错误信息
            var msg = eval("msg=" + returntext);
            if (msg.result == "1") {
                alert("操作成功");
                window.location.reload(true);
            }
            else {
                alert(msg.msg); //出错信息

            }


            break;
        default:
            //document.location = document.location;

    }
}
function rightMenu(pId, State, Type, Top, Pink, ContributionID, event) {
    var toolMenu = new WebFXMenu;


    if (Type == RealLink) {
        //toolMenu.add(new WebFXMenuItem('查看','javascript:doing("view","'+ pId +'")','查看文档内容'));

        if (ContributionID != '0') {
            toolMenu.add(new WebFXMenuItem('查看批注(来稿)', 'javascript:doing("note","' + ContributionID + '")', '查看批注(来稿)'));
        }
        //toolMenu.add(new WebFXMenuItem('编辑','javascript:doing("edit","'+ pId +'")','编辑文档'));
        //toolMenu.add(new WebFXMenuItem('删除','javascript:doing("del","'+ pId +'")', '删除文档'));
        toolMenu.add(new WebFXMenuItem('剪切', 'javascript:doing("cut","' + pId + '")', '剪切文档'));
        toolMenu.add(new WebFXMenuItem('复制', 'javascript:doing("copy","' + pId + '")', '复制文档'));
        toolMenu.add(new WebFXMenuSeparator());
        //toolMenu.add(new WebFXMenuItem('创建虚链接', 'javascript:doing("createLink","' + pId + '")', '创建虚链接'));
       // toolMenu.add(new WebFXMenuItem('创建索引链接', 'javascript:doing("createIndexLink","' + pId + '")', '创建索引链接'));
        //toolMenu.add(new WebFXMenuItem('查看链接状态', 'javascript:doing("viewLinkState","' + pId + '")', '查看链接状态'));
    } else {
        //toolMenu.add(new WebFXMenuItem('查看','javascript:doing("view","'+ pId +'")','查看文档内容'));
        //toolMenu.add(new WebFXMenuItem('删除','javascript:doing("del","'+ pId +'")', '删除文档'));
        toolMenu.add(new WebFXMenuItem('剪切', 'javascript:doing("cut","' + pId + '")', '剪切文档'));
        toolMenu.add(new WebFXMenuItem('复制', 'javascript:doing("copy","' + pId + '")', '复制文档'));
       // toolMenu.add(new WebFXMenuItem('查看链接状态', 'javascript:doing("viewLinkState","' + pId + '")', '查看链接状态'));


    }

    toolMenu.add(new WebFXMenuSeparator());

    toolMenu.add(new WebFXMenuItem('置顶设置', 'javascript:doing("topIt","' + pId + '")', '置顶设置'));

    toolMenu.add(new WebFXMenuItem('精华设置', 'javascript:doing("pinkIt","' + pId + '")', '精华设置'));
    toolMenu.add(new WebFXMenuItem('排序权重设置', 'javascript:doing("sortIt","' + pId + '")', '排序权重设置'));




    if (State == UnPublish) {
        toolMenu.add(new WebFXMenuSeparator());
        //toolMenu.add(new WebFXMenuItem('发布','javascript:doing("publish","'+ pId +'")','发布文档'));

    } else if (State == Publish) {
        toolMenu.add(new WebFXMenuSeparator());
        //toolMenu.add(new WebFXMenuItem('浏览发布','javascript:doing("viewpublish","'+ pId +'")','浏览发布'));
        toolMenu.add(new WebFXMenuItem('复制发布URL', 'javascript:doing("copyURL","' + pId + '")', '复制发布URL'));
        toolMenu.add(new WebFXMenuItem('获取发布URL', 'javascript:doing("getURL","' + pId + '")', '获取发布URL'));
        //toolMenu.add(new WebFXMenuItem('更新发布','javascript:doing("RePubContent","'+ pId +'")','更新发布'));
        toolMenu.add(new WebFXMenuItem('取消发布', 'javascript:doing("unpublish","' + pId + '")', '取消发布'));
        toolMenu.add(new WebFXMenuItem('临时取消发布', 'javascript:doing("tempUnPublish","' + pId + '")', '临时取消发布'));

    } else if (State == Publish && Type == IndexLink) {
        toolMenu.add(new WebFXMenuSeparator());
        //toolMenu.add(new WebFXMenuItem('浏览发布','javascript:doing("viewpublish","'+ pId +'")','浏览发布'));
        toolMenu.add(new WebFXMenuItem('复制发布URL', 'javascript:doing("copyURL","' + pId + '")', '复制发布URL'));
        toolMenu.add(new WebFXMenuItem('获取发布URL', 'javascript:doing("getURL","' + pId + '")', '获取发布URL'));

    }

    $('#menudata').html(toolMenu.toString());

    elo = window.event ? window.event.srcElement : event.target;
    toolMenu.left = event.clientX;
    toolMenu.top = event.clientY + document.body.scrollTop;
    toolMenu.show();

    //initrightmenu();

}
function going() {
    var selVal = getSelectVal();
    var val = $("#actionMap").val();
    if (val.indexOf('all_') == -1) {
        if (selVal == '') { alert('请选择要操作的内容'); return false; }
    }


    switch (val) {
        case 'RePubContent': //更新
            doing('RePubContent', selVal);
            break;
        case 'PubContent': //发布
            doing('PubContent', selVal);
            break;
        case 'unpublish': break;
            doing('unpublish', selVal);
        case 'tempUnPublish':
            doing('tempUnPublish', selVal);
            break;
        case 'copy':
            doing('copy', 'ids');
            break;
        case 'cut': //批量转移
            doing('cut', 'ids');
            break;
        case 'top': //批量置顶
            doing('topIt', 'ids');
            break;
        case 'pink': //批量精华
            doing('pinkIt', 'ids');
            break;
        case 'del': //批量删除
            if (confirm('确定批量删除')) {
                var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_delete_doc&nodeid=' + NodeID + '&id=' + selVal, async: false }).responseText;
                //alert(returntext); //调试错误信息
                var msg = eval("msg=" + returntext);
                if (msg.result == "1") {
                    alert("操作成功");
                    window.location.reload(true);
                }
                else {
                    alert(msg.msg); //出错信息

                }
            }
            break;
        case 'destroy':
            if (confirm("确认永久删除吗，该操作将不可恢复！")) {
                var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_delete_destroy&nodeid=' + NodeID + '&id=' + selVal, async: false }).responseText;
                // alert(returntext); //调试错误信息
                var msg = eval("msg=" + returntext);
                if (msg.result == "1") {
                    alert("删除成功");
                    window.location.reload(true);
                }
                else {
                    alert(msg.msg); //出错信息
                }
            }
            break;
        case 'createLink':
            doing('createLink', 'ids');
            break;
        case 'createIndexLink':
            doing('createIndexLink', 'ids');
            break;
        case 'all_unpublish': //结点全部取消发布
            window.location.href = 'admin_publish.aspx?ac=ConcelPubAll&nodeid=' + NodeID;
            break;
        case 'all_tempUnpublish': //结点全部临时取消发布
            window.location.href = 'admin_publish.aspx?ac=ConcelPubAll&nodeid=' + NodeID;
            break;
        case 'all_republish': //结点全部重新发布
            window.location.href = 'admin_publish.aspx?ac=RePubAll&nodeid=' + NodeID;
            break;

    }
}

function bind() {
    $("#ddlPublishStatus").attr("onchange", "doing('advanced_search', this.options[this.selectedIndex].value)");
    PubStatus == undefined ? "" : PubStatus;
    $("#ddlPublishStatus").val(PubStatus);
}